package belf.migrate.engine.ddl.synonym.oracle;

import belf.migrate.api.model.QualifiersModel;
import belf.migrate.api.table.schema.Catalog;
import belf.migrate.engine.ddl.BaseDDLConvert;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Oracle2KingbaseSynonymConvert extends BaseDDLConvert {

    public Oracle2KingbaseSynonymConvert(String objectName, String sql, Catalog sourceCatalog, Catalog sinkCatalog,
                                         String schema, QualifiersModel qualifiersModel) {
        super(objectName, sql, sourceCatalog, sinkCatalog, schema, qualifiersModel);
    }

    @Override
    public String convert() {
        // FIXME: 目前Oracle的同义词到达梦的转换，先简单这么处理（删除DM不支持的“EDITIONABLE”），后续再完善
        Pattern pattern = Pattern.compile("\\sEDITIONABLE\\s", Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(sql);
        String result = matcher.replaceAll(" ");
        return result;
    }
}
